{% macro runway(r='') -%}
<div class="form-group runway">
  <input type="hidden" name="runway" value="{{ "%s:%s:%s:%s"|format(r.number, r.length, r.width, r.surface) }}">
  <label class="col-lg-1 control-label">Runway</label>
  <div class="col-lg-1">
    <input type="text" class="form-control" name="runway-number" placeholder="number" value="{{ r.number if r != "" }}">
  </div>
  <label class="col-lg-1 control-label">Length</label>
  <div class="col-lg-2">
    <input type="text" class="form-control" name="runway-length" placeholder="length" value="{{ r.length if r != "" }}">
  </div>
  <label class="col-lg-1 control-label">Width</label>
  <div class="col-lg-2">
    <input type="text" class="form-control" name="runway-width" placeholder="width" value="{{ r.width if r != "" }}">
  </div>
  <label class="col-lg-1 control-label">Surface</label>
  <div class="col-lg-1">
    <select class="form-control" name="runway-surface">
      <option value="paved" {{ "selected=selected" if r != "" and r.surface == "paved"}}>Paved</option>
      <option value="turf" {{ "selected=selected" if r != "" and r.surface == "turf"}}>Turf</option>
    </select>
  </div>
  <div class="col-lg-1">
    <button type="button" class="btn btn-default delete-runway"><span class="glyphicon glyphicon-trash"></span></button>
  </div>
</div>
{%- endmacro %}


{% macro landing_form(flight) -%}
<div class="container">
  <form action='/landing' method='POST'>
    <div class='control-group'>
      <label>Landings on</label>
      {% for r in airport.runways %}
      {% set runwayid = airport.key.id() + '-' + r.number %}
        <label class='control-label' for='{{ runwayid }}'>
          <strong>{{ r.number }}</strong>
        </label>
        <div class='controls'>
          <input type='number' class='input-small' name='runway' placeholder='# landings' value='{{ flight.landings[runwayid] if runwayid in flight.landings }}'>
        </div>
      {% endfor %}
      <input type='hidden' name='airport' value='{{ airport.key.urlsafe() }}'>
      <input type='hidden' name='flight' value='{{ flight.key.urlsafe() }}'>
      <div class='form-actions pull-left'>
        <button type='submit' class='btn btn-primary'>Save</button>
        <span class='help-inline text-success' style='display: none;'>Success!</span>
      </div>
    </div>
  </form>
</div>
{%- endmacro %}

{% macro quick_add_form(flight) -%}
<form class='form-inline' action='#' method='POST'>
  <input type='text' class='input-mini' name='id' placeholder='ID'>
  <input type='text' class='input-mini' name='runway' placeholder='runway'>
  <input type='number' class='input-small' name='landings' placeholder='# landings'>
  <input type='hidden' name='flight' value='{{ flight.key.urlsafe() }}'>
  <button type='submit' class='btn btn-primary'>Add</button>
</form>
{%- endmacro %}
